#include <stdio.h>
#include <unistd.h>
#include<stdint.h>
#include<fcntl.h>
#include<sys/timerfd.h>

int main()
{
    int timefd = timerfd_create(CLOCK_MONOTONIC, 0);
    if(timefd < 0){
        perror("timer_create error");
        return -1;
    }
    struct itimerspec itime;
    itime.it_value.tv_sec = 1;//第一次触发时间
    itime.it_value.tv_nsec = 0;
    itime.it_interval.tv_sec = 1;//第一次之后每次触发的间隔
    itime.it_interval.tv_nsec = 0;
    timerfd_settime(timefd, 0, &itime, nullptr);
    //fd    flag:0表示相对开机时间   struct itimerspec*new不知道干嘛

    while(true){
        uint64_t times;
        int ret = read(timefd, &times, sizeof(times));
        if(ret < 0){
            perror("read error!");
        }
        printf("超时%ld次\n", times);
    }
    close(timefd);
}